<template>
  <el-container class="home-container">
    <!-- 侧边栏 -->
    <el-aside width="200px">
      <img class="schoolname" src="../assets/img/顶部导航@2x.png" alt="" />
      <el-menu
        background-color="#064db4"
        text-color="#fff"
        active-text-color="#ffd04b"
        :unique-opened="true"
        router
        :default-active="activePath"
      >
        <!-- 一级菜单 -->
        <el-submenu
          :index="item.id + ''"
          v-for="item in leftlist"
          :key="item.id"
        >
          <!-- 一级菜单的模板区域 -->
          <template slot="title">
            <!-- 图标 -->
            <div @click="headrouter(item.id)">
              <img class="onemenusimg" :src="item.image" alt="" width="16px " />
              <!-- 文本 -->
              <span>{{ item.yijilistname }}</span>
            </div>

            <!-- <i class="el-submenu__icon-arrow el-icon-arrow-down"></i> -->
          </template>

          <!-- 二级菜单 -->
          <el-menu-item
            :index="'/' + subitem.path"
            v-for="subitem in item.children"
            :key="subitem.id"
            @click="saveNavState('/' + subitem.path)"
          >
            <span class="erjispan">{{ subitem.erjilistname }}</span>
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <!-- 页面主题区域 -->
    <el-container>
      <!-- 头部区域-->
      <el-header>
        <div class="home-header">
          <div class="fl">
            <!-- 面包屑导航区域 -->
            <img class="breadimg" src="../assets/img/形状@2x.png" alt="" />
            <el-breadcrumb separator-class="el-icon-arrow-right">
              <el-breadcrumb-item :to="{ path: '/headpage' }"
                >欢迎来到山西工商学院网格化信息管理系统！</el-breadcrumb-item
              >
              <!-- <el-breadcrumb-item>活动管理</el-breadcrumb-item> -->
            </el-breadcrumb>
          </div>
          <div class="fr username">
            <img src="../assets/img/tishi@2x.png" alt="" />
            <img src="../assets/img/pifu@2x.png" alt="" />
            <div class="xtztgl" @click="xtztgl">
              <img src="../assets/img/touxiang.jpg" alt="" />
              <span>管理员</span>
            </div>
          </div>
          <div class="tcxt">
            <button>个人设置</button>
            <button @click="loginout">退出系统</button>
          </div>
        </div>
      </el-header>
      <!-- 右侧内容主题区域 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import $ from "../assets/jquery.min.js";
import a from "../../public/jsondata/menus.js";
export default {
  data() {
    return {
      leftlist: [],
      // 被激活的链接地址
      activePath: "",
    };
  },
  created() {
    if (this.$route.path == "/headpage") {
      this.activePath = "";
    } else {
      this.activePath = window.sessionStorage.getItem("activePath");
    }
    this.getMenuList();
  },
  methods: {
    //获取所有的菜单
    getMenuList() {
      // console.log(JSON.parse(JSON.stringify(a)).data);
      this.leftlist = JSON.parse(JSON.stringify(a)).data;
      // console.log(this.leftlist);
    },
    headrouter(index) {
      if (index == 1) {
        this.$router.push("/headpage");
      }
    },
    // 保存链接激活
    saveNavState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
    },
    //退出系统
    xtztgl() {
      $(".tcxt").toggle()
    },
    loginout(){
      window.sessionStorage.clear();
      this.$router.push('/login')

    }
  },
};
</script>

<style lang="less" scoped>
.tcxt {
  display: none;
  position: fixed;
  right: 11px;
  top: 60px;
  width: 84px;
  z-index: 10;
  height: 77px;
  background: antiquewhite;
}

.el-header {
  background-color: #fff;
  box-shadow: 5px 0px 8px 0px #ccc;
  position: relative;
  .home-header {
    width: 100%;
    height: 26px;
    margin: 17px 0;
    // background-color: aquamarine;
    .fl {
      height: 100%;
      width: 350px;
      // background-color: yellow;
    }
    .fr {
      height: 100%;
      width: 142px;
      // background-color: tomato;
    }
  }
}
.home-container {
  height: 100%;
}
.el-aside {
  overflow: hidden;
  background-color: #064db4;
  .schoolname {
    width: 100%;
    height: 60px;
  }
}
.el-main {
  background-color: #f5f5f5;
  overflow: hidden;
}
.el-menu {
  border: none;
}
.el-submenu {
  padding-left: 13px;
}
.onemenusimg {
  padding-right: 9px;
  padding-bottom: 2px;
}
.el-submenu__icon-arrow {
  color: #fff;
}
.erjispan {
  padding-left: 6px;
}
li:first-of-type div::after {
  color: #fff !important;
}
.el-breadcrumb {
  line-height: 26px;
  padding-left: 24px;
  font-size: 16px;
  font-family: emoji;
}
.breadimg {
  width: 16px;
  height: 16px;
  position: absolute;
  padding-top: 6px;
}
.username {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  img {
    height: 18px;
    width: 18px;
  }
  div {
    position: relative;
    width: 77px;
    img {
      cursor: pointer;
      width: 30px;
      height: 30px;
      border-radius: 50%;
    }
    span {
      cursor: pointer;
      position: absolute;
      right: 0;
      top: 10px;
      // height: 100%;
      // line-height:100% ;
      font-size: 14px;
      color: #333;
    }
  }
}
</style>